package com.jzj.jzjctripapi.utils;

import com.jzj.jzjctripapi.domain.request.AuthenticationListRequst;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Mazhenming
 * @date 2023/11/9 15:53
 * @desciption：请求实体数据划分
 */
public class RequestEntityUtil {
    //list：要进行分批处理的列表
    //size：每批的大小
    public static <AuthenticationListRequst> List<AuthenticationListRequst> batch(List<AuthenticationListRequst> authenticationListRequst, int size) {
        int totalSize = authenticationListRequst.size();
        int batchCount = (totalSize + size - 1) / size;
        List<AuthenticationListRequst> batches = new ArrayList<>(batchCount);
        for (int i = 0; i < batchCount; i++) {
            int startIndex = i * size;
            int endIndex = Math.min(startIndex + size, totalSize);
            batches.add((AuthenticationListRequst) authenticationListRequst.subList(startIndex, endIndex));
        }
        return batches;
    }

}

